package com.ruoyi.web.controller.jypc;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jypc.domain.Carorder;
import com.ruoyi.jypc.service.ICarorderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用车订单Controller
 * 
 * @author HWJ
 * @date 2022-11-02
 */
@RestController
@RequestMapping("/jypc/carorder")
public class CarorderController extends BaseController {
	@Autowired
	private ICarorderService carorderService;

	/**
	 * 查询用车订单列表
	 */
	@PreAuthorize("@ss.hasPermi('jypc:carorder:list')")
	@GetMapping("/list")
	public TableDataInfo list(Carorder carorder) {
		startPage();
		List<Carorder> list = carorderService.selectCarorderList(carorder);
		return getDataTable(list);
	}

	/**
	 * 查询车辆列表
	 */
	@PreAuthorize("@ss.hasPermi('jypc:carorder:list')")
	@GetMapping("/listAll")
	public TableDataInfo listAll(Carorder carorder) {
		List<Carorder> list = carorderService.selectCarorderListAll();
		return getDataTable(list);
	}
	
	
	
	
	/**
	 * 查询用车订单列表
	 *//*
		 * @PreAuthorize("@ss.hasPermi('jypc:carorder:list')")
		 * 
		 * @GetMapping("/listpointAll") public TableDataInfo listpointAll() {
		 * 
		 * List<Carorder> list = carorderService.selectCarorderListpointAll(); return
		 * getDataTable(list); }
		 */

	/**
	 * 导出用车订单列表
	 */
	@PreAuthorize("@ss.hasPermi('jypc:carorder:export')")
	@Log(title = "用车订单", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, Carorder carorder) {
		List<Carorder> list = carorderService.selectCarorderList(carorder);
		ExcelUtil<Carorder> util = new ExcelUtil<Carorder>(Carorder.class);
		util.exportExcel(response, list, "用车订单数据");
	}

	/**
	 * 获取用车订单详细信息
	 */
	@PreAuthorize("@ss.hasPermi('jypc:carorder:query')")
	@GetMapping(value = "/{orderid}")
	public AjaxResult getInfo(@PathVariable("orderid") Long orderid) {
		return AjaxResult.success(carorderService.selectCarorderByOrderid(orderid));
	}

	/**
	 * 新增用车订单
	 */
	@PreAuthorize("@ss.hasPermi('jypc:carorder:add')")
	@Log(title = "用车订单", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody Carorder carorder) {
		return toAjax(carorderService.insertCarorder(carorder));
	}

	/**
	 * 修改用车订单
	 */
	@PreAuthorize("@ss.hasPermi('jypc:carorder:edit')")
	@Log(title = "用车订单", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody Carorder carorder) {
		return toAjax(carorderService.updateCarorder(carorder));
	}

	/**
	 * 删除用车订单
	 */
	@PreAuthorize("@ss.hasPermi('jypc:carorder:remove')")
	@Log(title = "用车订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderids}")
	public AjaxResult remove(@PathVariable Long[] orderids) {
		return toAjax(carorderService.deleteCarorderByOrderids(orderids));
	}
}
